home *** CD-ROM | disk | FTP | other *** search
- // Dynamic link library implementation of a generic pre/post-processor
-
- #include "NSDLL.h"
- #include <windows.h>
-
- #define matrix(i,j) output[i + buffer.yOffset - j*buffer.steps]
-
- typedef struct {
- int steps;
- int currentX, currentY;
- int xChannel, yChannel;
- int plotChannel;
- int yOffset;
- int outputAxonLength;
- boolean allChannelFlag;
- NSFloat minX, maxX;
- NSFloat minY, maxY;
- NSFloat xInterval, yInterval;
- NSFloat inputHoldValue;
- } BufferData;
-
- BufferData buffer = {0, 0, 0, 0, 0, 0, 0, 0, FALSE, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
-
- /*****************************************/
- /* Activation of Postprocessor component */
- __declspec(dllexport) BOOL performPrePost(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *input, // Pointer to the input data
- NSFloat *output, // Pointer to the output data
- int rows, // Number of rows of data
- int cols, // Number of cols of output data, can be changed to reflect a diffenent number for the input data
- BOOL preprocessor // Flag to indicate whether this is a preprocessor or postprocessor
- )
- {
- if (buffer.allChannelFlag) {
- int i, firstLargestOutputIndex=0, secondLargestOutputIndex=0;
- NSFloat firstLargestOutput=input[0], secondLargestOutput=-1.0E-99f;
- for (i=1;i<buffer.outputAxonLength;i++) {
- if (input[i] > firstLargestOutput) {
- firstLargestOutputIndex = i;
- firstLargestOutput = input[i];
- }
- else if (input[i] > secondLargestOutput) {
- secondLargestOutputIndex = i;
- secondLargestOutput = input[i];
- }
- }
- matrix(buffer.currentX, buffer.currentY) = input[secondLargestOutputIndex] - input[firstLargestOutputIndex] + 1;
- }
- else
- matrix(buffer.currentX, buffer.currentY) = input[buffer.plotChannel];
-
- if (++buffer.currentX >= buffer.steps) {
- buffer.currentX = 0;
- if (++buffer.currentY >= buffer.steps) {
- buffer.currentY = 0;
- return TRUE;
- }
- }
- return FALSE; // Return whether to inject this sample or to call performPrePost with another sample
- }
-
- /**********************************/
- /* Activation of output component */
- __declspec(dllexport) void performInput(
- DLLData *instance, // Pointer to instance data (may be NULL)
- NSFloat *data, // Pointer to the data
- int rows, // Number of rows of data
- int cols // Number of cols of data
- )
- {
- int i, length=rows*cols;
- for (i=0;i<length;i++)
- data[i] = buffer.inputHoldValue;
- data[buffer.xChannel] = buffer.minX + buffer.currentX*buffer.xInterval;
- data[buffer.yChannel] = buffer.minY + buffer.currentY*buffer.yInterval;
- }
-
- /******************************************/
- /* Called every time the network is reset */
- __declspec(dllexport) void networkReset(
- DLLData *instance // Pointer to instance data (may be NULL)
- )
- {
- buffer.currentX = 0;
- buffer.currentY = 0;
- }
-
- /******************************************/
- /* Management of instance data (OPTIONAL) */
- __declspec(dllexport) DLLData *allocPrePost(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int *rows, // Number of rows of output data, can be changed to reflect a diffenent number for the input data
- int *cols, // Number of cols of output data, can be changed to reflect a diffenent number for the input data
- BOOL preprocessor // Flag to indicate whether this is a preprocessor or postprocessor
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- if (preprocessor)
- MessageBox(NULL, "Discriminant Function DLL should only be used as a postprocessor", "Warning", MB_OK);
- setParameterName(instance, 1, 1, "Steps", TRUE);
- setIntParameter(instance, 1, 1, 20, FALSE);
- setParameterName(instance, 2, 1, "All Channels", TRUE);
- setBoolParameter(instance, 2, 1, FALSE, FALSE);
- setParameterName(instance, 3, 1, "Plot Channel", TRUE);
- setIntParameter(instance, 3, 1, 0, FALSE);
- buffer.steps = getIntParameter(instance, 1, 1);
- buffer.allChannelFlag = getBoolParameter(instance, 2, 1);
- buffer.plotChannel = getIntParameter(instance, 3, 1);
- if (buffer.steps < 2)
- buffer.steps = 2;
- if (buffer.plotChannel >= *rows * *cols)
- buffer.plotChannel = *rows * *cols - 1;
- setIntParameter(instance, 1, 1, buffer.steps, TRUE);
- setIntParameter(instance, 3, 1, buffer.plotChannel, TRUE);
- buffer.outputAxonLength = *rows * *cols;
- if (buffer.outputAxonLength==1) {
- buffer.allChannelFlag = FALSE;
- setBoolParameter(instance, 2, 1, FALSE, FALSE);
- }
- *rows = *cols = buffer.steps;
- buffer.xInterval = (buffer.maxX-buffer.minX)/(buffer.steps-1);
- buffer.yInterval = (buffer.maxY-buffer.minY)/(buffer.steps-1);
- buffer.yOffset = buffer.steps*(buffer.steps - 1);
- networkReset(instance);
- return instance;
- }
-
- __declspec(dllexport) void freePrePost(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
-
- __declspec(dllexport) DLLData *allocInput(
- DLLData *oldInstance, // Pointer to the last instance if reallocating
- int rows, // Number of rows of data
- int cols // Number of cols of data
- )
- {
- DLLData *instance = allocDLLInstance(oldInstance);
- setParameterName(instance, 1, 0, "X Channel", TRUE);
- setIntParameter(instance, 1, 0, 0, FALSE);
- setParameterName(instance, 1, 1, "Min X", TRUE);
- setFloatParameter(instance, 1, 1, -1.0f, FALSE);
- setParameterName(instance, 1, 2, "Max X", TRUE);
- setFloatParameter(instance, 1, 2, 1.0f, FALSE);
- setParameterName(instance, 2, 0, "Y Channel", TRUE);
- setIntParameter(instance, 2, 0, 1, FALSE);
- setParameterName(instance, 2, 1, "Min Y", TRUE);
- setFloatParameter(instance, 2, 1, -1.0f, FALSE);
- setParameterName(instance, 2, 2, "Max Y", TRUE);
- setFloatParameter(instance, 2, 2, 1.0f, FALSE);
- setParameterName(instance, 3, 0, "Other Hold", TRUE);
- setFloatParameter(instance, 3, 0, 0.0f, FALSE);
- buffer.xChannel = getIntParameter(instance, 1, 0);
- buffer.minX = getFloatParameter(instance, 1, 1);
- buffer.maxX = getFloatParameter(instance, 1, 2);
- buffer.yChannel = getIntParameter(instance, 2, 0);
- buffer.minY = getFloatParameter(instance, 2, 1);
- buffer.maxY = getFloatParameter(instance, 2, 2);
- buffer.inputHoldValue = getFloatParameter(instance, 3, 0);
- if (buffer.xChannel >= rows*cols) {
- buffer.xChannel = rows*cols-1;
- setIntParameter(instance, 1, 0, buffer.xChannel, TRUE);
- }
- if (buffer.yChannel >= rows*cols) {
- buffer.yChannel = rows*cols-1;
- setIntParameter(instance, 2, 0, buffer.yChannel, TRUE);
- }
- if (buffer.minX >= buffer.maxX) {
- buffer.maxX = buffer.minX + 0.1f;
- setFloatParameter(instance, 1, 2, buffer.maxX, TRUE);
- }
- if (buffer.minY >= buffer.maxY) {
- buffer.maxY = buffer.minY + 0.1f;
- setFloatParameter(instance, 1, 2, buffer.maxY, TRUE);
- }
- buffer.xInterval = (buffer.maxX-buffer.minX)/(buffer.steps-1);
- buffer.yInterval = (buffer.maxY-buffer.minY)/(buffer.steps-1);
- networkReset(instance);
- return instance;
- }
-
- __declspec(dllexport) void freeInput(DLLData *instance)
- {
- freeDLLInstance(instance);
- }
-
- __declspec(dllexport) int exemplars(DLLData *instance)
- {
- return buffer.steps * buffer.steps;
- }
-